/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.common.publicity.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpStatus;
import com.icinfo.cloud.common.security.util.UserUtil;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.enums.DocumentKindEnum;
import com.icinfo.cloud.provider.common.enums.YesOrNoEnum;
import com.icinfo.cloud.provider.common.exception.BusinessException;
import com.icinfo.cloud.provider.common.utils.BaseUtil;
import com.icinfo.cloud.provider.punish.common.caseregister.service.IRegisterCommonService;
import com.icinfo.cloud.provider.punish.common.datareport.dto.CaseDataReportRequestCommonDto;
import com.icinfo.cloud.provider.punish.common.datareport.dto.RevokeDecisionOrCaseInfoDto;
import com.icinfo.cloud.provider.punish.common.datareport.enums.CaseDataReportOptTypeEnum;
import com.icinfo.cloud.provider.punish.common.datareport.enums.ReportDataTypeEnum;
import com.icinfo.cloud.provider.punish.common.datareport.mapper.CaseDataReportRecordMapper;
import com.icinfo.cloud.provider.punish.common.datareport.model.CaseDataReportRecord;
import com.icinfo.cloud.provider.punish.common.datareport.service.ICaseDataReportRecordService;
import com.icinfo.cloud.provider.punish.common.datareport.service.impl.CaseDataReportDecisionServiceImpl;
import com.icinfo.cloud.provider.punish.common.documentoperate.enums.DocumentStatusEnum;
import com.icinfo.cloud.provider.punish.common.publicity.dto.CasePublicityListPageRequest;
import com.icinfo.cloud.provider.punish.common.publicity.dto.CasePublicityModifyRecordDetailQueryDto;
import com.icinfo.cloud.provider.punish.common.publicity.dto.CasePublicityModifyRecordPageRequest;
import com.icinfo.cloud.provider.punish.common.publicity.dto.PublicityModifyRecordSaveDto;
import com.icinfo.cloud.provider.punish.common.publicity.enums.CasePublicityModifyEnum;
import com.icinfo.cloud.provider.punish.common.publicity.enums.PublicityStatusEnum;
import com.icinfo.cloud.provider.punish.common.publicity.mapper.CasePublicityModifyRecordMapper;
import com.icinfo.cloud.provider.punish.common.publicity.model.CasePublicityModifyRecord;
import com.icinfo.cloud.provider.punish.common.publicity.service.ICasePublicityModifyRecordService;
import com.icinfo.cloud.provider.punish.common.publicity.vo.*;
import com.icinfo.cloud.provider.punish.config.model.ConfigBusiParamDocumentInfo;
import com.icinfo.cloud.provider.punish.config.service.IConfigBusiParamDocumentInfoService;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseDocumentRecordDelRequest;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseDocumentRecordDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseDocumentRecordQueryDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseMainDetailAuxiliaryInfoRequest;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.CaseTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.HandleTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.PartiesReasonTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.PartyTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.CaseDocumentRecordMapper;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.CaseHandlePersonRecordMapper;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.CaseMainDetailAuxiliaryInfoMapper;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.CaseMainDetailInfoMapper;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.CaseDocumentRecord;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.CaseHandlePersonRecord;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.CaseMainDetailAuxiliaryInfo;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.CaseMainDetailInfo;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.*;
import com.icinfo.cloud.xzcf.provider.member.userinfo.dto.UserDTO;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.service.support.MyBatisServiceSupport;
import com.icinfo.framework.mybatis.mapper.entity.Example;
import com.icinfo.framework.mybatis.pagehelper.page.PageMethod;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ObjectUtils;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 描述: 公示记录表 case_publicity_modify_record 对应的Service接口实现类.<br>
 *
 * @author framework generator
 * @date 2022年10月13日
 */
@Service
public class CasePublicityModifyRecordServiceImpl extends MyBatisServiceSupport implements ICasePublicityModifyRecordService {
    /**
     * 日志记录器
     */
    private static final Logger logger = LoggerFactory.getLogger(CasePublicityModifyRecordServiceImpl.class);

    @Resource
    private CasePublicityModifyRecordMapper casePublicityModifyRecordMapper;
    @Resource
    private ICaseMainInfoService caseMainInfoService;
    @Resource
    private ICaseMainDetailAuxiliaryInfoService caseMainDetailAuxiliaryInfoService;
    @Resource
    private CaseMainDetailInfoMapper caseMainDetailInfoMapper;
    @Resource
    private IConfigBusiParamDocumentInfoService configBusiParamDocumentInfoService;
    @Resource
    private CaseDocumentRecordMapper caseDocumentRecordMapper;
    @Resource
    private ICaseDataReportRecordService caseDataReportRecordService;
    @Resource
    private ICasePartiesRecordService casePartiesRecordService;
    @Resource
    private ICaseMainDetailInfoService caseMainDetailInfoService;
    @Resource
    private CaseDataReportDecisionServiceImpl caseDataReportDecisionService;
    @Resource
    private CaseDataReportDecisionServiceImpl decisionService;
    @Resource
    private ICaseDocumentRecordService caseDocumentRecordService;
    @Resource
    private CaseHandlePersonRecordMapper caseHandlePersonRecordMapper;
    @Resource
    private CaseDataReportRecordMapper caseDataReportRecordMapper;
    @Resource
    private CaseMainDetailAuxiliaryInfoMapper caseMainDetailAuxiliaryInfoMapper;
    @Value("${isCheckHandleSign}")
    private String isCheckHandleSign;
    @Resource
    private IRegisterCommonService commonService;

    @Override
    public List<CasePublicityListVo> getPublicityPageList(CasePublicityListPageRequest pageRequest) {
        UserDTO userDTO = UserUtil.getUserInfo();
        String deptType = userDTO.getDeptType();
        if (Constant.STRING_2.equals(deptType)) {
            pageRequest.setCaseDeptCode(userDTO.getDeptCode());
        }
        pageRequest.setUserId(userDTO.getUserId() + "");
        pageRequest.setCaseOrgCode(userDTO.getOrgCode());
        List<String> partyTypeList = pageRequest.getPartySubclassTypeList();
        if (ObjectUtil.isNotEmpty(partyTypeList)) {
            List<String> legalPartyTypeList = new ArrayList();
            for (String partySubclassType : partyTypeList) {
                if (partySubclassType.startsWith(PartyTypeEnum.PERSON.getCode() + "_")) {
                    pageRequest.setPersonPartyType(partySubclassType.replace(PartyTypeEnum.PERSON.getCode() + "_", ""));
                } else if (partySubclassType.startsWith(PartyTypeEnum.LEGAL.getCode() + "_")) {
                    legalPartyTypeList.add(partySubclassType.replace(PartyTypeEnum.LEGAL.getCode() + "_", ""));
                }
            }
            pageRequest.setLegalPartyTypeList(legalPartyTypeList);
        }
        PageMethod.startPage(pageRequest.getPageNum(), pageRequest.getLength(), pageRequest.getOrderBy());
        List<CasePublicityListVo> voList = casePublicityModifyRecordMapper.selectPublicityPageList(pageRequest);

        for (CasePublicityListVo publicityListVo : voList) {
            String caseId = publicityListVo.getCaseId();

            //1.循环设置办案人员
            Example example = new Example(CaseHandlePersonRecord.class);
            example.createCriteria().andEqualTo("caseId", caseId).andEqualTo("status", Constant.STRING_1);
            example.orderBy("handlePersonType").asc();
            List<CaseHandlePersonRecord> handlePersonRecords = caseHandlePersonRecordMapper.selectByExample(example);
            for (CaseHandlePersonRecord caseHandlePersonRecord : handlePersonRecords) {
                if (Constant.STRING_1.equals(caseHandlePersonRecord.getHandlePersonType())) {
                    publicityListVo.setMainHandlePerson(caseHandlePersonRecord.getHandlePersonName());
                } else if (Constant.STRING_2.equals(caseHandlePersonRecord.getHandlePersonType())) {
                    publicityListVo.setHelpHandlePerson(caseHandlePersonRecord.getHandlePersonName());
                }
            }
            String handPersonName = handlePersonRecords.stream().map(p -> p.getHandlePersonName()).collect(Collectors.joining(","));
            publicityListVo.setHandlePersonName(handPersonName);

            //2、当事人信息
            List<CasePartiesRecordVo> casePartiesRecords = casePartiesRecordService.getCasePartiesInfoVoList(caseId);
            if (ObjectUtil.isNotEmpty(casePartiesRecords)) {
                if (ObjectUtil.isNotEmpty(publicityListVo.getPartyId())) {
                    List<CasePartiesRecordVo> filterParty = casePartiesRecords.stream().filter(e -> e.getPartyId().equals(publicityListVo.getPartyId())).collect(Collectors.toList());
                    if (ObjectUtil.isNotEmpty(filterParty)) {
                        if (PartyTypeEnum.LEGAL.getCode().equals(filterParty.get(0).getPartyType())) {
                            publicityListVo.setUniscid(filterParty.get(0).getPartyIdentityCode());
                        }
                        publicityListVo.setPartyName(filterParty.get(0).getPartyName());
                        publicityListVo.setPartyType(filterParty.get(0).getPartyType());
                    }
                } else {
                    if (casePartiesRecords.size() > 1) {
                        publicityListVo.setPartyType("multitude");
                        publicityListVo.setPartyName(casePartiesRecords.get(0).getPartyName() + "等" + casePartiesRecords.size() + "个");
                    } else {
                        CasePartiesRecordVo casePartiesRecordVo = casePartiesRecords.get(0);
                        if (PartyTypeEnum.LEGAL.getCode().equals(casePartiesRecordVo.getPartyType())) {
                            publicityListVo.setUniscid(casePartiesRecordVo.getPartyIdentityCode());
                        }
                        publicityListVo.setPartyId(casePartiesRecordVo.getPartyId());
                        publicityListVo.setPartyName(casePartiesRecordVo.getPartyName());
                        publicityListVo.setPartyType(casePartiesRecordVo.getPartyType());
                    }
                }
            }

            //3、循环处理可操作文书
            publicityListVo.setCasePublicityOperateInfoVoList(getCasePublicityOperateInfoVoList(publicityListVo));

            publicityListVo.setCaseType(CaseTypeEnum.getValueByCode(publicityListVo.getCaseType()));
            publicityListVo.setPublicityStatusDesc(PublicityStatusEnum.getValueByCode(publicityListVo.getPublicityStatus()));
        }
        return voList;
    }

    private List<CasePublicityOperateInfoVo> getCasePublicityOperateInfoVoList(CasePublicityListVo publicityListVo) {
        //申请更正公示审批表
        String correctPublicityKindCode = DocumentKindEnum.DOC_KIND_DT1SQGZGSSPB.getCode();
        //申请撤销公示审批表
        String revokePublicityKindCode = DocumentKindEnum.DOC_KIND_DT1SQCXGSSPB.getCode();
        List<String> documentKindCodeList = new ArrayList<>();
        documentKindCodeList.add(correctPublicityKindCode);
        documentKindCodeList.add(revokePublicityKindCode);

        String publicityStatus = publicityListVo.getPublicityStatus();
        String partyId = publicityListVo.getPartyId();
        String busiParamId = publicityListVo.getBusiParamId();
        List<CasePublicityOperateInfoVo> casePublicityOperateInfoVoList = new ArrayList<>();

        CaseDocumentRecordQueryDto queryDto = new CaseDocumentRecordQueryDto();
        queryDto.setCaseId(publicityListVo.getCaseId());
        queryDto.setDocumentKindCodeList(documentKindCodeList);
        String isDisable = "0";
        String documentId = "";

        List<CaseDocumentRecordDto> caseDocumentRecordDtoList = caseDocumentRecordService.getDocumentRecordDtoList(queryDto);
        if (ObjectUtil.isNotEmpty(caseDocumentRecordDtoList) && caseDocumentRecordDtoList.size() > 0) {
            //查询撤销公示文书记录
            List<CaseDocumentRecordDto> revokePublicityRecord = caseDocumentRecordDtoList.stream()
                    .filter(e -> e.getDocumentKindCode().equals(revokePublicityKindCode) && (ObjectUtil.isEmpty(partyId) || partyId.equals(e.getPartyId()))).collect(Collectors.toList());

            String correctDocumentCatalogCode = "";
            String revokeDocumentCatalogCode = "";
            if (ObjectUtil.isNotEmpty(revokePublicityRecord) && revokePublicityRecord.size() > 0) {
                CaseDocumentRecordDto documentRecordDto = revokePublicityRecord.get(0);
                if (DocumentStatusEnum.CHECK_END.getCode().equals(revokePublicityRecord.get(0).getDocumentApprovalStatus())) {
                    return casePublicityOperateInfoVoList;
                }
                revokeDocumentCatalogCode = documentRecordDto.getDocumentCatalogCode();
                documentId = documentRecordDto.getId();
            }
            //存在待审批列表
            List<CaseDocumentRecordDto> checkingDocumentRecord = caseDocumentRecordDtoList.stream()
                    .filter(e -> DocumentStatusEnum.CHECKING.getCode().equals(e.getDocumentApprovalStatus())).collect(Collectors.toList());
            if (ObjectUtil.isNotEmpty(checkingDocumentRecord) && checkingDocumentRecord.size() > 0) {
                isDisable = "1";
            }
            //获取更正公示documentCatalogCode
            List<CaseDocumentRecordDto> correctPublicityRecord = caseDocumentRecordDtoList.stream()
                    .filter(e -> e.getDocumentKindCode().equals(revokePublicityKindCode) && (ObjectUtil.isEmpty(partyId) || partyId.equals(e.getPartyId()))).collect(Collectors.toList());
            if (ObjectUtil.isNotEmpty(correctPublicityRecord) && correctPublicityRecord.size() > 0) {
                correctDocumentCatalogCode = correctPublicityRecord.get(0).getDocumentCatalogCode();
                documentId = correctPublicityRecord.get(0).getId();
            }

            //予以公示
            if (PublicityStatusEnum.NO_PUBLICITY.getCode().equals(publicityStatus) || PublicityStatusEnum.PUBLICITY.getCode().equals(publicityStatus)) {
                //更正公示
                CasePublicityOperateInfoVo operateInfoVo = assembleCasePublicityOperateInfoVo(publicityListVo, correctPublicityKindCode, revokeDocumentCatalogCode, isDisable, documentId);
                casePublicityOperateInfoVoList.add(operateInfoVo);
            }
            if (PublicityStatusEnum.PUBLICITY.getCode().equals(publicityStatus)) {
                // 撤销公示
                CasePublicityOperateInfoVo operateInfoVo2 = assembleCasePublicityOperateInfoVo(publicityListVo, revokePublicityKindCode, correctDocumentCatalogCode, isDisable, documentId);
                casePublicityOperateInfoVoList.add(operateInfoVo2);
            }

        } else {
            //予以公示
            if (PublicityStatusEnum.NO_PUBLICITY.getCode().equals(publicityStatus)
                    || PublicityStatusEnum.PUBLICITY.getCode().equals(publicityStatus)) {
                //更正公示
                CasePublicityOperateInfoVo operateInfoVo = assembleCasePublicityOperateInfoVo(publicityListVo, correctPublicityKindCode, "", isDisable, documentId);
                casePublicityOperateInfoVoList.add(operateInfoVo);
            }
            if (PublicityStatusEnum.PUBLICITY.getCode().equals(publicityStatus)) {
                // 撤销公示
                CasePublicityOperateInfoVo operateInfoVo2 = assembleCasePublicityOperateInfoVo(publicityListVo, revokePublicityKindCode, "", isDisable, documentId);
                casePublicityOperateInfoVoList.add(operateInfoVo2);
            }
        }
        return casePublicityOperateInfoVoList;
    }

    /**
     * 描述：组装可操作文书
     *
     * @param publicityListVo     宣传列表签证官
     * @param documentKindCode
     * @param documentCatalogCode 文件目录的代码
     * @param isDisable           是禁用
     * @return {@link CasePublicityOperateInfoVo }
     * @author shishengyao
     * @date 2022/10/24
     */
    private CasePublicityOperateInfoVo assembleCasePublicityOperateInfoVo(CasePublicityListVo publicityListVo,
                                                                          String documentKindCode,
                                                                          String documentCatalogCode,
                                                                          String isDisable,
                                                                          String documentId) {
        String caseId = publicityListVo.getCaseId();

        CasePublicityOperateInfoVo operateInfoVo = new CasePublicityOperateInfoVo();
        if (DocumentKindEnum.DOC_KIND_DT1SQCXGSSPB.getCode().equals(documentKindCode)) {
            operateInfoVo.setOperateName("申请撤销");
        }
        if (DocumentKindEnum.DOC_KIND_DT1SQGZGSSPB.getCode().equals(documentKindCode)) {
            operateInfoVo.setOperateName("申请更正");
        }
        operateInfoVo.setDocumentCatalogCode(documentCatalogCode);
        if (ObjectUtil.isEmpty(documentCatalogCode)) {
            ConfigBusiParamDocumentInfo busiParamInfo2 = configBusiParamDocumentInfoService.getDocumentInfoByDocumentKindCode(publicityListVo.getBusiParamId(), documentKindCode);
            operateInfoVo.setDocumentCatalogCode(busiParamInfo2.getDocumentCatalogCode());
        }
        operateInfoVo.setDocumentKindCode(operateInfoVo.getDocumentKindCode());
        operateInfoVo.setIsDisable(isDisable);
        return operateInfoVo;

    }

    @Override
    public List<CasePublicityModifyRecordVo> getPublicityModifyPageList(CasePublicityModifyRecordPageRequest pageRequest) {
        UserDTO userDTO = UserUtil.getUserInfo();
        pageRequest.setUserId(userDTO.getUserId()+"");
        PageMethod.startPage(pageRequest.getPageNum(), pageRequest.getLength(), pageRequest.getOrderBy());
        List<CasePublicityModifyRecordVo> voList = casePublicityModifyRecordMapper.selectPublicityModifyPageList(pageRequest);
        for (CasePublicityModifyRecordVo recordVo : voList) {
            recordVo.setApprovalStatus(DocumentStatusEnum.getValueByCode(recordVo.getApprovalStatus()));
        }
        return voList;
    }

    @Override
    public List<CasePublicityModifyRecordDetailVo> getCasePublicityRecordDetail(CasePublicityModifyRecordDetailQueryDto queryDto) {
        String caseId = queryDto.getCaseId();
        String partyId = queryDto.getPartyId();
        List<CasePublicityModifyRecordDetailVo> voList = new ArrayList<>();
        //查询是否有变更请求
        List<CasePublicityModifyRecord> modifyList = getPublicityModifyListByCaseIdAndPartyId(caseId, partyId);
        CasePublicityInfo casePublicityInfo = new CasePublicityInfo();
        if (ObjectUtil.isEmpty(modifyList)) {
            CasePublicityModifyRecordDetailVo detailVo = new CasePublicityModifyRecordDetailVo();
            if (caseMainInfoService.validateIsNeedPassPartyId(null, caseId)) {
                if (ObjectUtils.isEmpty(partyId)) {
                    throw new BusinessException("多当事人分别处罚时请指定当事人id");
                }
                //多当事人分别处罚时查询案件详情补充表
                CaseMainDetailAuxiliaryInfoRequest request = new CaseMainDetailAuxiliaryInfoRequest(caseId, partyId);
                List<CaseMainDetailAuxiliaryInfo> caseMainDetailAuxiliaryList = caseMainDetailAuxiliaryInfoService.getCaseMainDetailAuxiliaryInfo(request);
                if (!ObjectUtils.isEmpty(caseMainDetailAuxiliaryList)) {
                    CaseMainDetailAuxiliaryInfo caseMainDetailAuxiliaryInfo = caseMainDetailAuxiliaryList.get(0);
                    BeanUtils.copyProperties(caseMainDetailAuxiliaryInfo, casePublicityInfo);
                    casePublicityInfo.setIsPublicity(caseMainDetailAuxiliaryInfo.getIsPublicity());
                    detailVo.setOperateTime(LocalDateTime.now());
                }
            } else {
                CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoMapper.selectByPrimaryKey(caseId);
                BeanUtils.copyProperties(caseMainDetailInfo, casePublicityInfo);
                casePublicityInfo.setIsPublicity(caseMainDetailInfo.getIsPublicity());
                detailVo.setOperateTime(LocalDateTime.now());
            }
            //公示相关信息处理
            if (YesOrNoEnum.YES.getCode().equals(casePublicityInfo.getIsPublicity())) {
                //默认未公示
                boolean isAlreadyPublicity = false;
                casePublicityInfo.setIsPublicityText("予以公示");
                //查询处罚决定最新上报记录
                CaseDataReportRecord latestReportRecord = caseDataReportRecordService.getLatestReportRecord(caseId, ReportDataTypeEnum.DECISION.getCode());
                casePublicityInfo.setIsAlreadyPublicity(YesOrNoEnum.NO.getCode());
                casePublicityInfo.setIsAlreadyPublicityText(YesOrNoEnum.NO.getDes());
                if (!ObjectUtils.isEmpty(latestReportRecord)) {
                    //校验是否已经公示,通过访问公示地址来判断
                    String publicUrl = latestReportRecord.getPublicUrl();
                    if (checkPublicUrl(publicUrl)) {
                        isAlreadyPublicity = true;
                        String publicDate = latestReportRecord.getPublicDate().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日"));
                        casePublicityInfo.setPublicityDate(publicDate);
                        casePublicityInfo.setIsAlreadyPublicity(YesOrNoEnum.YES.getCode());
                        casePublicityInfo.setIsAlreadyPublicityText(YesOrNoEnum.YES.getDes());
                        casePublicityInfo.setPublicitySite("政务服务网");
                        casePublicityInfo.setPublicityUrl(latestReportRecord.getPublicUrl());
                    }
                }

                //未公示处理
                if (!isAlreadyPublicity) {
                    //待送达的，在公示地址处展示“文书待送达，暂未公示”，
                    //送达后未公示前，在公示地址处展示“已上报浙江政务服务网，待完成公示后在此处查看公示地址”
                    CaseDocumentRecordQueryDto recordQueryDto = new CaseDocumentRecordQueryDto();
                    recordQueryDto.setCaseId(caseId);
                    recordQueryDto.setDocumentKindCode(Constant.STRING_KIND_CODE_CFJDS);
                    recordQueryDto.setPartyId(partyId);
                    CaseDocumentRecordDetailVo caseDocumentRecordDetailVo = caseDocumentRecordMapper.selectCaseDocumentRecordDetail(recordQueryDto);
                    if (!ObjectUtils.isEmpty(caseDocumentRecordDetailVo)) {
                        if (ObjectUtils.isEmpty(caseDocumentRecordDetailVo.getSentTime())) {
                            casePublicityInfo.setPublicityUrl("文书待送达，暂未公示");
                        } else {
                            casePublicityInfo.setPublicityUrl("已上报政务服务网，待完成公示后在此处查看公示地址");
                        }
                    }
                }

            } else {
                casePublicityInfo.setIsPublicityText("不予公示");
            }
            detailVo.setOperateType(Constant.STRING_0);
            detailVo.setPublicityInfo(casePublicityInfo);
            detailVo.setOperateTypeShowText(PublicityStatusEnum.getValueByCode(casePublicityInfo.getIsPublicity()));
            detailVo.setPublicityOperateName("初次公示");
            detailVo.setPublicityModifyRecordId(BaseUtil.createUid());
            voList.add(detailVo);
        } else {
            //有变更记录
            for (CasePublicityModifyRecord modifyRecord : modifyList) {
                CasePublicityModifyRecordDetailVo vo = new CasePublicityModifyRecordDetailVo();
                vo.setPublicityModifyRecordId(modifyRecord.getId());
                vo.setPublicityOperateName(modifyRecord.getOperateType());
                vo.setOperateType(modifyRecord.getOperateType());
                vo.setOperateTypeShowText(CasePublicityModifyEnum.getValueByCode(modifyRecord.getOperateType()));
                CasePublicityModifyInfo casePublicityModifyInfo = new CasePublicityModifyInfo();
                BeanUtils.copyProperties(modifyRecord, casePublicityModifyInfo);
                vo.setPublicityModifyInfo(casePublicityModifyInfo);
                vo.setOperateTime(modifyRecord.getPublicitySubmitTime());
                //查询文书记录
                if (ObjectUtil.isNotEmpty(modifyRecord.getDocumentId())) {
                    CaseDocumentRecord caseDocumentRecord = caseDocumentRecordMapper.selectByPrimaryKey(modifyRecord.getDocumentId());
                    if (ObjectUtil.isNotEmpty(caseDocumentRecord)) {
                        if (ObjectUtil.isNotEmpty(caseDocumentRecord.getDocumentUrlAfterSign())) {
                            vo.setApprovalDocumentUrl(caseDocumentRecord.getDocumentUrlAfterSign());
                        } else if (ObjectUtil.isNotEmpty(caseDocumentRecord.getDocumentUrlAfterSeal())) {
                            vo.setApprovalDocumentUrl(caseDocumentRecord.getDocumentUrlAfterSeal());
                        } else {
                            vo.setApprovalDocumentUrl(caseDocumentRecord.getDocumentUrl());
                        }
                        vo.setApprovalDocumentUrl(caseDocumentRecord.getDocumentUrl());
                    }
                }

                //查询初次公示状态
                if (CasePublicityModifyEnum.FIRST_PUBLICITY.getCode().equals(modifyRecord.getOperateType())) {
                    vo.setOperateTypeShowText(PublicityStatusEnum.getValueByCode(modifyRecord.getPublicityStatus()));
                    CaseDataReportRecord caseDataReportRecord = caseDataReportRecordMapper.selectByPrimaryKey(modifyRecord.getDataReportRecordId());
                    casePublicityInfo.setIsPublicity(modifyRecord.getPublicityStatus());
                    casePublicityInfo.setIsPublicityText(PublicityStatusEnum.getValueByCode(modifyRecord.getPublicityStatus()));
                    casePublicityInfo.setPublicityContent(modifyRecord.getPublicityContent());
                    casePublicityInfo.setNoPublicityReason(modifyRecord.getNoPublicityReason());
                    casePublicityInfo.setNoPublicityRemark(modifyRecord.getNoPublicityRemark());
                    casePublicityInfo.setIsAlreadyPublicity(YesOrNoEnum.NO.getCode());
                    casePublicityInfo.setIsAlreadyPublicityText(YesOrNoEnum.NO.getDes());
                    casePublicityInfo.setPublicitySite("政务服务网");
                    if (ObjectUtil.isNotEmpty(caseDataReportRecord)) {
                        casePublicityInfo.setPublicityUrl(caseDataReportRecord.getPublicUrl());
                        String publicDate = caseDataReportRecord.getPublicDate().format(DateTimeFormatter.ofPattern("yyyy年MM月dd日"));
                        if (ObjectUtil.isNotEmpty(modifyRecord.getStatus()) && Constant.STRING_0.equals(modifyRecord.getStatus())) {
                            casePublicityInfo.setIsAlreadyPublicity(YesOrNoEnum.YES.getCode());
                            casePublicityInfo.setIsAlreadyPublicityText(YesOrNoEnum.YES.getDes());
                        }
                        casePublicityInfo.setPublicityDate(publicDate);
                        casePublicityInfo.setPublicityUrl(caseDataReportRecord.getPublicUrl());

                    }
                    vo.setPublicityInfo(casePublicityInfo);
                }
                voList.add(vo);
            }
        }
        return voList;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int removeCasePublicityModifyRecordDetail(String id) {
        CasePublicityModifyRecord modifyRecord = casePublicityModifyRecordMapper.selectByPrimaryKey(id);
        CaseDocumentRecordVo caseDocumentRecordInfo = caseDocumentRecordService.getCaseDocumentRecordInfo(modifyRecord.getDocumentId());
        //删除文书
        CaseDocumentRecordDelRequest delRequest = new CaseDocumentRecordDelRequest();
        delRequest.setCaseId(modifyRecord.getCaseId());
        delRequest.setPartyId(caseDocumentRecordInfo.getDocumentCatalogCode());
        delRequest.setDocumentCatalogCode(caseDocumentRecordInfo.getDocumentCatalogCode());
        delRequest.setDocumentId(modifyRecord.getDocumentId());
        caseDocumentRecordService.delCaseDocumentRecordInfo(delRequest);

        Example example = new Example(CasePublicityModifyRecord.class);
        example.createCriteria().andEqualTo("id", id);
        CasePublicityModifyRecord deleteRecord = new CasePublicityModifyRecord();
        deleteRecord.setIsDelete(Constant.STRING_1);
        return casePublicityModifyRecordMapper.updateByExampleSelective(deleteRecord, example);
    }

    @Override
    public int removeCasePublicityModifyRecordDetailByDocumentId(String documentId) {
        Example example = new Example(CasePublicityModifyRecord.class);
        example.createCriteria().andEqualTo("documentId", documentId);
        CasePublicityModifyRecord modifyRecord = new CasePublicityModifyRecord();
        modifyRecord.setIsDelete(Constant.STRING_1);
        return casePublicityModifyRecordMapper.updateByExampleSelective(modifyRecord, example);
    }

    @Override
    public List<CasePublicityModifyRecord> getPublicityModifyListByCaseIdAndPartyId(String caseId, String partyId) {
        Example example = new Example(CasePublicityModifyRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("caseId", caseId).andEqualTo("isDelete", Constant.STRING_0);
        if (ObjectUtil.isNotEmpty(partyId)) {
            criteria.andEqualTo("partyId", partyId);
        }
        example.orderBy("createTime").desc();
        return casePublicityModifyRecordMapper.selectByExample(example);
    }

    @Override
    public CasePublicityModifyRecord getLastPublicityModifyRecord(String caseId, String partyId, String operateType) {
        Example example = new Example(CasePublicityModifyRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("caseId", caseId);
        if (ObjectUtil.isNotEmpty(partyId)) {
            criteria.andEqualTo("partyId", partyId);
        }
        if (ObjectUtil.isNotEmpty(operateType)) {
            criteria.andEqualTo("operateType", operateType);
        }
        example.orderBy("createTime").desc();
        List<CasePublicityModifyRecord> modifyRecordList = casePublicityModifyRecordMapper.selectByExample(example);
        if (ObjectUtil.isNotEmpty(modifyRecordList) && modifyRecordList.size() > 0) {
            return modifyRecordList.get(0);
        }
        return null;
    }

    @Override
    public CasePublicityModifyRecord getPublicityModifyListByDocumentId(String documentId) {
        Example example = new Example(CasePublicityModifyRecord.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("documentId", documentId);
        example.orderBy("createTime").desc();
        List<CasePublicityModifyRecord> modifyRecordList = casePublicityModifyRecordMapper.selectByExample(example);
        if (ObjectUtil.isNotEmpty(modifyRecordList) && modifyRecordList.size() > 0) {
            return modifyRecordList.get(0);
        }
        return null;
    }

    @Override
    public int saveCasePublicityModifyRecord(PublicityModifyRecordSaveDto saveDto) {
        String caseId = saveDto.getCaseId();
        String partyId = saveDto.getPartyId();
        String operateType = CasePublicityModifyEnum.getCodeByDocumentKindCode(saveDto.getDocumentKindCode());

        if ("true".equals(isCheckHandleSign)) {
            boolean isAllowDataReport = caseDataReportRecordService.getIsAllowDataReport(caseId);
            if (!isAllowDataReport) {
                throw new BusinessException("办案部门未开启数据上报按钮，无法变更公示。请前往：办案配置-单位参数配置，进行设置。");
            }
        }
        CaseMainDetailInfo mainDetailInfo = caseMainDetailInfoService.getCaseMainDetailByCaseId(caseId);
        HashMap<String, Object> dataMap = saveDto.getDataMap();
        //申请人签名
        String applyPersonSignPic = ObjectUtil.isNotEmpty(dataMap.get("applyPersonSignPic")) ? dataMap.get("applyPersonSignPic").toString() : "";
        //  签名校验
        if (ObjectUtil.isEmpty(dataMap.get("applyPersonSignPic"))) {
            UserDTO userInfo = UserUtil.getUserInfo();
            applyPersonSignPic = commonService.getHandleSignData(userInfo.getUserId() + "");
            if ("true".equals(isCheckHandleSign)) {
                if (ObjectUtil.isEmpty(applyPersonSignPic)) {
                    throw new BusinessException("办案人员" + userInfo.getRealName() + "的签名为空!");
                }
            }
        }
        dataMap.put("applyPersonSignPic", applyPersonSignPic);
        //组装更新数据

        String modifyPublicityReason = ObjectUtil.isNotEmpty(dataMap.get("modifyReason")) ? dataMap.get("modifyReason").toString() : "";
        String modifyDesc = ObjectUtil.isNotEmpty(dataMap.get("modifyDesc")) ? dataMap.get("modifyDesc").toString() : "";
        CasePublicityModifyRecord updateModifyRecord = new CasePublicityModifyRecord();
        updateModifyRecord.setModifyReason(modifyPublicityReason);
        updateModifyRecord.setModifyDesc(modifyDesc);
        if (CasePublicityModifyEnum.CORRECT_PUBLICITY.getCode().equals(operateType)) {
            String publicityContent = ObjectUtil.isNotEmpty(dataMap.get("publicityContent")) ? dataMap.get("publicityContent").toString() : "";
            updateModifyRecord.setPublicityStatus(PublicityStatusEnum.PUBLICITY.getCode());
            updateModifyRecord.setPublicityContent(publicityContent);
        } else if (CasePublicityModifyEnum.REVOKE_PUBLICITY.getCode().equals(operateType)) {
            updateModifyRecord.setPublicityStatus(PublicityStatusEnum.NO_PUBLICITY.getCode());
            updateModifyRecord.setNoPublicityReason(modifyPublicityReason);
            updateModifyRecord.setNoPublicityRemark(modifyDesc);
        }
        updateModifyRecord.setModifyReason(modifyPublicityReason);
        updateModifyRecord.setOperateType(operateType);
        LocalDateTime nowDate = LocalDateTime.now();
        //查询是否有记录
        CasePublicityModifyRecord modifyListByDocumentId = getPublicityModifyListByDocumentId(saveDto.getDocumentId());
        if (ObjectUtil.isNotEmpty(modifyListByDocumentId)) {
            Example example = new Example(CasePublicityModifyRecord.class);
            example.createCriteria().andEqualTo("id", modifyListByDocumentId.getId());
            updateModifyRecord.setModifyDesc(modifyDesc);
            updateModifyRecord.setId(BaseUtil.createUid());
            updateModifyRecord.setDocumentId(saveDto.getDocumentId());
            return casePublicityModifyRecordMapper.updateByPrimaryKeySelective(updateModifyRecord);
        } else {
            String partyType = "";
            String partyName = "";
            CaseMainInfoVo caseMainInfo = caseMainInfoService.getCaseMainInfo(caseId);
            String handleType = caseMainInfo.getHandleType();
            String partiesReasonType = caseMainInfo.getCasePartiesReasonType();
            if (!HandleTypeEnum.PART_PUNISH.getCode().equals(handleType) || Constant.STRING_2.equals(partiesReasonType)) {
                //不为分别处罚
                List<CasePartiesRecordVo> casePartiesRecords = casePartiesRecordService.getCasePartiesInfoVoList(caseId);
                if (ObjectUtil.isNotEmpty(casePartiesRecords)) {
                    if (HandleTypeEnum.MERGE_PUNISH.getCode().equals(handleType) && casePartiesRecords.size() > 1) {
                        partyType = "multitude";
                        partyId = casePartiesRecords.stream().map(p -> p.getPartyId()).collect(Collectors.joining(","));
                        partyName = casePartiesRecords.get(0).getPartyName() + "等" + casePartiesRecords.size() + "个当事人";
                    } else {
                        partyType = casePartiesRecords.get(0).getPartyType();
                        partyId = casePartiesRecords.get(0).getPartyId();
                        partyName = casePartiesRecords.get(0).getPartyName();
                    }
                }
            }
            //分别处罚
            if (PartiesReasonTypeEnum.MULTIPLE_PARTIES.getCode().equals(partiesReasonType) && HandleTypeEnum.PART_PUNISH.getCode().equals(handleType)) {
                if (ObjectUtils.isEmpty(partyId)) {
                    throw new BusinessException("多当事人分别处罚时请指定当事人id");
                }
                //分别处罚
                CasePartiesRecordVo partiesRecordVo = casePartiesRecordService.getCasePartiesInfoByPartyId(caseId, partyId);
                partyType = partiesRecordVo.getPartyType();
                partyId = partiesRecordVo.getPartyId();
                partyName = partiesRecordVo.getPartyName();
            }

            List<CasePublicityModifyRecord> publicityModifyRecordList = getPublicityModifyListByCaseIdAndPartyId(caseId, partyId);
            //没有初次公示记录塞一条
            if (ObjectUtils.isEmpty(publicityModifyRecordList)) {
                ConfigBusiParamDocumentInfo configBusiParamDocumentInfo = configBusiParamDocumentInfoService.getDocumentInfoByDocumentKindCode(caseMainInfo.getBusiParamId(), DocumentKindEnum.DOC_KIND_CFJDS.getCode());
                CaseDocumentRecord caseDocumentRecord = caseDocumentRecordService.getCaseDocumentRecord(caseId, configBusiParamDocumentInfo.getDocumentCatalogCode(), partyId);
                if (!ObjectUtils.isEmpty(caseDocumentRecord) && !DocumentStatusEnum.SENT.getCode().equals(caseDocumentRecord.getDocumentSentStatus())) {
                    throw new BusinessException("请在处罚决定书送达之后进行公示变更");
                }
                CasePublicityModifyRecord firstCasePublicityModifyRecord = new CasePublicityModifyRecord();
                if (caseMainInfoService.validateIsNeedPassPartyId(null, caseId)) {
                    if (ObjectUtils.isEmpty(partyId)) {
                        throw new BusinessException("多当事人分别处罚时请指定当事人id");
                    }
                    //多当事人分别处罚时查询案件详情补充表
                    CaseMainDetailAuxiliaryInfoRequest request = new CaseMainDetailAuxiliaryInfoRequest(caseId, partyId);
                    List<CaseMainDetailAuxiliaryInfo> caseMainDetailAuxiliaryList = caseMainDetailAuxiliaryInfoService.getCaseMainDetailAuxiliaryInfo(request);
                    if (!ObjectUtils.isEmpty(caseMainDetailAuxiliaryList)) {
                        CaseMainDetailAuxiliaryInfo caseMainDetailAuxiliaryInfo = caseMainDetailAuxiliaryList.get(0);
                        firstCasePublicityModifyRecord.setPublicityContent(caseMainDetailAuxiliaryInfo.getPublicityContent());
                        firstCasePublicityModifyRecord.setNoPublicityReason(caseMainDetailAuxiliaryInfo.getNoPublicityReason());
                        firstCasePublicityModifyRecord.setNoPublicityRemark(caseMainDetailAuxiliaryInfo.getNoPublicityRemark());
                        firstCasePublicityModifyRecord.setPublicityStatus(caseMainDetailAuxiliaryInfo.getIsPublicity());
                        firstCasePublicityModifyRecord.setPartyName(partyName);
                        firstCasePublicityModifyRecord.setPunishDocumentNumber(caseMainDetailAuxiliaryInfo.getPunishDocumentNumber());
                    }
                } else {
                    firstCasePublicityModifyRecord.setPublicityContent(mainDetailInfo.getPublicityContent());
                    firstCasePublicityModifyRecord.setNoPublicityReason(mainDetailInfo.getNoPublicityReason());
                    firstCasePublicityModifyRecord.setNoPublicityRemark(mainDetailInfo.getNoPublicityRemark());
                    firstCasePublicityModifyRecord.setPublicityStatus(mainDetailInfo.getIsPublicity());
                    firstCasePublicityModifyRecord.setPunishDocumentNumber(mainDetailInfo.getPunishDocumentNumber());
                    firstCasePublicityModifyRecord.setPartyName(partyName);
                }

                CaseDataReportRecord latestReportRecord = caseDataReportRecordService.getLatestReportRecord(caseId, ReportDataTypeEnum.DECISION.getCode());
                firstCasePublicityModifyRecord.setStatus(YesOrNoEnum.NO.getCode());
                //默认未公示
                boolean isAlreadyPublicity = false;
                if (!ObjectUtils.isEmpty(latestReportRecord)) {
                    firstCasePublicityModifyRecord.setDataReportRecordId(latestReportRecord.getId());
                    //校验是否已经公示,通过访问公示地址来判断
                    String publicUrl = latestReportRecord.getPublicUrl();
                    if (checkPublicUrl(publicUrl)) {
                        isAlreadyPublicity = true;
                        firstCasePublicityModifyRecord.setStatus(YesOrNoEnum.YES.getCode());
                    }
                }

                firstCasePublicityModifyRecord.setPublicitySubmitTime(caseDocumentRecord.getDocumentApprovalTime());
                firstCasePublicityModifyRecord.setCreateTime(nowDate);
                firstCasePublicityModifyRecord.setId(BaseUtil.createUid());
                firstCasePublicityModifyRecord.setIsDelete(Constant.STRING_0);
                firstCasePublicityModifyRecord.setOperateType(Constant.STRING_0);
                firstCasePublicityModifyRecord.setCaseId(caseId);
                firstCasePublicityModifyRecord.setPartyId(partyId);
                firstCasePublicityModifyRecord.setPartyName(partyName);
                firstCasePublicityModifyRecord.setPartyType(partyType);
                casePublicityModifyRecordMapper.insertSelective(firstCasePublicityModifyRecord);
                updateModifyRecord.setPunishDocumentNumber(firstCasePublicityModifyRecord.getPunishDocumentNumber());
                nowDate = nowDate.plusSeconds(5);
            } else {
                CasePublicityModifyRecord casePublicityModifyRecord = publicityModifyRecordList.get(0);
                updateModifyRecord.setPunishDocumentNumber(publicityModifyRecordList.get(0).getPunishDocumentNumber());
                partyId = casePublicityModifyRecord.getPartyId();
                partyType = casePublicityModifyRecord.getPartyType();
                partyName = casePublicityModifyRecord.getPartyName();
            }
            //新增一条数据数据
            updateModifyRecord.setModifyReason(modifyPublicityReason);
            updateModifyRecord.setModifyDesc(modifyDesc);
            updateModifyRecord.setId(BaseUtil.createUid());
            updateModifyRecord.setCreateTime(nowDate);
            updateModifyRecord.setIsDelete(Constant.STRING_0);
            updateModifyRecord.setDocumentId(saveDto.getDocumentId());
            updateModifyRecord.setCaseId(caseId);
            updateModifyRecord.setPartyId(partyId);
            updateModifyRecord.setPartyName(partyName);
            updateModifyRecord.setPartyType(partyType);
            updateModifyRecord.setStatus(Constant.STRING_0);
            return casePublicityModifyRecordMapper.insertSelective(updateModifyRecord);
        }

    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public String dealPublicityModifyAfterFinishApproval(String caseId, String documentKindCode, String documentId) {
        Example updateExample = new Example(CasePublicityModifyRecord.class);
        updateExample.createCriteria().andEqualTo("documentId", documentId);
        CasePublicityModifyRecord publicityModifyRecord = new CasePublicityModifyRecord();
        publicityModifyRecord.setStatus(Constant.STRING_1);
        publicityModifyRecord.setPublicitySubmitTime(LocalDateTime.now());
        casePublicityModifyRecordMapper.updateByExampleSelective(publicityModifyRecord, updateExample);
        if (DocumentKindEnum.DOC_KIND_DT1SQCXGSSPB.getCode().equals(documentKindCode)) {
            dealFinishRevokePublicity(caseId, documentId);
        }
        if (DocumentKindEnum.DOC_KIND_DT1SQGZGSSPB.getCode().equals(documentKindCode)) {
            dealFinishCorrectPublicity(caseId, documentId);
        }
        return null;
    }

    /**
     * 描述：处理最终撤销公示
     *
     * @author shishengyao
     * @date 2022/10/21
     */
    public void dealFinishRevokePublicity(String caseId, String documentId) {
        CaseMainInfoVo caseMainInfo = caseMainInfoService.getCaseMainInfo(caseId);
        String handleType = caseMainInfo.getHandleType();
        String partiesReasonType = caseMainInfo.getCasePartiesReasonType();

        //查询公示变更信息
        CasePublicityModifyRecord modifyRecord = getPublicityModifyListByDocumentId(documentId);
        if (!Constant.STRING_2.equals(handleType) || Constant.STRING_2.equals(partiesReasonType)) {
            //不为分别处罚 则更新案件详情表
            //更新宽表公示状态
            CaseMainDetailInfo updateCaseMainDetail = new CaseMainDetailInfo();
            updateCaseMainDetail.setIsPublicity(PublicityStatusEnum.NO_PUBLICITY.getCode());
            updateCaseMainDetail.setPublicityContent(modifyRecord.getPublicityContent());
            updateCaseMainDetail.setNoPublicityReason(modifyRecord.getNoPublicityReason());
            updateCaseMainDetail.setNoPublicityRemark(modifyRecord.getNoPublicityRemark());
            updateCaseMainDetail.setCaseId(caseId);
            caseMainDetailInfoMapper.updateByPrimaryKeySelective(updateCaseMainDetail);
            try {
                //单当事人单案由 更新补充表数据
                CaseMainDetailAuxiliaryInfo caseMainDetailAuxiliaryInfo = new CaseMainDetailAuxiliaryInfo();
                caseMainDetailAuxiliaryInfo.setCaseId(caseId);
                caseMainDetailAuxiliaryInfo.setIsPublicity(PublicityStatusEnum.NO_PUBLICITY.getCode());
                caseMainDetailAuxiliaryInfo.setPublicityContent(modifyRecord.getPublicityContent());
                caseMainDetailAuxiliaryInfo.setNoPublicityReason(modifyRecord.getNoPublicityReason());
                caseMainDetailAuxiliaryInfo.setNoPublicityRemark(modifyRecord.getNoPublicityRemark());
                caseMainDetailAuxiliaryInfoService.editSpecialParamSingle(caseMainDetailAuxiliaryInfo);
            }catch (Exception e){
                e.printStackTrace();
            }

        }
        if (Constant.STRING_3.equals(partiesReasonType) && Constant.STRING_2.equals(handleType)) {
            Example example = new Example(CaseMainDetailAuxiliaryInfo.class);
            example.createCriteria().andEqualTo("caseId", caseId).andEqualTo("partyId", modifyRecord.getPartyId());
            List<CaseMainDetailAuxiliaryInfo> caseMainDetailAuxiliaryInfos = caseMainDetailAuxiliaryInfoMapper.selectByExample(example);
            if (null != caseMainDetailAuxiliaryInfos && caseMainDetailAuxiliaryInfos.size() > 0) {
                CaseMainDetailAuxiliaryInfo caseMainDetailAuxiliaryInfo = caseMainDetailAuxiliaryInfos.get(0);
                CaseMainDetailAuxiliaryInfo updateCaseMainDetailAuxiliaryInfo = new CaseMainDetailAuxiliaryInfo();
                updateCaseMainDetailAuxiliaryInfo.setId(caseMainDetailAuxiliaryInfo.getId());
                updateCaseMainDetailAuxiliaryInfo.setIsPublicity(PublicityStatusEnum.NO_PUBLICITY.getCode());
                updateCaseMainDetailAuxiliaryInfo.setPublicityContent(modifyRecord.getPublicityContent());
                updateCaseMainDetailAuxiliaryInfo.setNoPublicityReason(modifyRecord.getNoPublicityReason());
                updateCaseMainDetailAuxiliaryInfo.setNoPublicityRemark(modifyRecord.getNoPublicityRemark());
                caseMainDetailAuxiliaryInfoMapper.updateByPrimaryKeySelective(updateCaseMainDetailAuxiliaryInfo);
            }
        }

        // 撤销公示
        RevokeDecisionOrCaseInfoDto dto = new RevokeDecisionOrCaseInfoDto(caseId, null, Constant.STRING_2, Constant.STRING_HORIZONTAL_BARS, modifyRecord.getPartyId());
        Result<String> result = caseDataReportDecisionService.revokeDecisionOrCaseInfo(dto);

        if ("true".equals(isCheckHandleSign)) {
            if (HttpStatus.HTTP_OK != result.getCode()) {
                throw new BusinessException("撤销公示失败：" + result.getMessage());
            }
        }

    }

    /**
     * 描述：处理最终更正公示
     *
     * @author shishengyao
     * @date 2022/10/21
     */
    public void dealFinishCorrectPublicity(String caseId, String documentId) {
        CasePublicityModifyRecord modifyRecord = getPublicityModifyListByDocumentId(documentId);
        CaseMainInfoVo caseMainInfo = caseMainInfoService.getCaseMainInfo(caseId);
        String handleType = caseMainInfo.getHandleType();
        String partiesReasonType = caseMainInfo.getCasePartiesReasonType();

        if (!Constant.STRING_2.equals(handleType) || Constant.STRING_2.equals(partiesReasonType)) {
            //不为分别处罚 则更新案件详情表
            //更新宽表公示状态
            CaseMainDetailInfo updateCaseMainDetail = new CaseMainDetailInfo();
            updateCaseMainDetail.setCaseId(caseId);
            updateCaseMainDetail.setIsPublicity(PublicityStatusEnum.PUBLICITY.getCode());
            updateCaseMainDetail.setPublicityContent(modifyRecord.getPublicityContent());
            caseMainDetailInfoMapper.updateByPrimaryKeySelective(updateCaseMainDetail);
            try {
                //单当事人单案由 更新补充表数据
                CaseMainDetailAuxiliaryInfo caseMainDetailAuxiliaryInfo = new CaseMainDetailAuxiliaryInfo();
                caseMainDetailAuxiliaryInfo.setCaseId(caseId);
                caseMainDetailAuxiliaryInfo.setIsPublicity(PublicityStatusEnum.PUBLICITY.getCode());
                caseMainDetailAuxiliaryInfo.setPublicityContent(modifyRecord.getPublicityContent());
                caseMainDetailAuxiliaryInfoService.editSpecialParamSingle(caseMainDetailAuxiliaryInfo);
            }catch (Exception e){
                e.printStackTrace();
            }

        }
        if (Constant.STRING_3.equals(partiesReasonType) && Constant.STRING_2.equals(handleType)) {
            Example example = new Example(CaseMainDetailAuxiliaryInfo.class);
            example.createCriteria().andEqualTo("caseId", caseId).andEqualTo("partyId", modifyRecord.getPartyId());
            List<CaseMainDetailAuxiliaryInfo> caseMainDetailAuxiliaryInfos = caseMainDetailAuxiliaryInfoMapper.selectByExample(example);
            if (null != caseMainDetailAuxiliaryInfos && caseMainDetailAuxiliaryInfos.size() > 0) {
                CaseMainDetailAuxiliaryInfo caseMainDetailAuxiliaryInfo = caseMainDetailAuxiliaryInfos.get(0);
                CaseMainDetailAuxiliaryInfo updateCaseMainDetailAuxiliaryInfo = new CaseMainDetailAuxiliaryInfo();
                updateCaseMainDetailAuxiliaryInfo.setId(caseMainDetailAuxiliaryInfo.getId());
                updateCaseMainDetailAuxiliaryInfo.setIsPublicity(PublicityStatusEnum.PUBLICITY.getCode());
                updateCaseMainDetailAuxiliaryInfo.setPublicityContent(modifyRecord.getPublicityContent());
                caseMainDetailAuxiliaryInfoMapper.updateByPrimaryKeySelective(updateCaseMainDetailAuxiliaryInfo);
            }
        }

        //数据上报推送
        CaseDataReportRequestCommonDto dto = new CaseDataReportRequestCommonDto();
        dto.setCaseId(caseId);
        dto.setOptType(CaseDataReportOptTypeEnum.U.getCode());
        /*List<CasePartiesInfoVo> partyInfoList = casePartiesRecordService.getCasePartiesInfoVo(caseId, modifyRecord.getPartyId());
        CasePartiesInfoVo casePartiesInfoVo = null;
        if (ObjectUtil.isNotEmpty(partyInfoList) && partyInfoList.size()>0){
            casePartiesInfoVo= partyInfoList.get(0);
        }*/
        Result<String> result = decisionService.singleCaseReport(dto, null, null);
        //todo屏蔽数据上报回调信息
        if ("true".equals(isCheckHandleSign)) {
            if (HttpStatus.HTTP_OK != result.getCode()) {
                throw new BusinessException("更正公示失败：" + result.getMessage());
            }
        }
    }



    /**
     * 描述： 校验公示地址是否存在
     *
     * @return {@link boolean}
     * @author: zhengqiang
     * @date: 2022/7/22
     * @param: url
     **/
    private boolean checkPublicUrl(String url) {
        if (ObjectUtil.isEmpty(url)){
            return false;
        }
        url=url.replace("https://www.zjzwfw.gov.cn","http://10.145.147.112:8581/proxy/zwfwwGs");
        String response = BaseUtil.sendGETRequest(url, new HashMap<>());
        if (ObjectUtils.isEmpty(response)) {
            return false;
        }
        return true;
    }
}
